{extend name="normal_base" /}
{block name="body"}
<div class="x-body">
    <blockquote class="layui-elem-quote" style="color: #AAAAAA">Tip ： 若填写了具体的区间值，则优先以业务额条件进行评级；当区间值为0时可表示：最小/最大值</blockquote>
    <!--<form class="layui-form" method="POST" action="{:url('star_level_config')}" id="from_id">-->
        <table class="layui-table" lay-skin="nob">
            <!--<colgroup>
                <col width="250">
                <col width="350">
                <col width="420">
                <col width="200">
                <col>
            </colgroup>-->
            {foreach name="config_info" item="vo"}
            <tr>
                <td>
                    <div class="layui-inline">
                        星级：<span class="star-level" level-value="{vo.star_level}">
                        {:str_repeat('<i class="fa fa-star"></i>', $vo.star_level)}
                    </span>
                    </div>
                </td>
                <td>
                    <div class="layui-inline">

                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" id="revenue_min-{$vo.id}" placeholder="￥" autocomplete="off" class="layui-input" value="{$vo.revenue_min}">
                        </div>
                        &nbsp;<span style="font-weight: bold"><</span>&nbsp; 业务额 &nbsp;<span style="font-weight: bold">≤</span>&nbsp;
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" id="revenue_max-{$vo.id}" placeholder="￥" autocomplete="off" class="layui-input" value="{$vo.revenue_max}">
                        </div>
                    </div>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <div class="layui-inline">
                        根据描述：
                        <div class="layui-input-inline" style="width: 300px;">
                            <input type="text" id="desc-{$vo.id}" autocomplete="off" class="layui-input" value="{$vo.desc}">
                        </div>
                    </div>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <div class="layui-input-inline">
                        <button class="layui-btn layui-btn-primary layui-btn-sm change-star-level-config" c-id="{$vo.id}">
                            <i class="layui-icon">&#xe605;</i>
                        </button>
                    </div>
                </td>
                <td>

                </td>
            </tr>
            {/foreach}
        </table>

<!--
    </form>-->
</div>

{/block}

{block name="script"}
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
                ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
        });

        //监听提交
        form.on('submit(edit)', function(data){
            $("#from_id").ajaxSubmit({
                beforeSubmit:function () {
                    //表单提交前
                },
                success:function (data) {
                    //console.log(JSON.stringify(data));
                    if (data.code == 1) {
                        layer.msg(data.msg,{icon:5,time:1500});
                    } else {
                        layer.alert("修改成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }
                }
            });
            return false;
        });

        $('.change-star-level-config').bind('click',function () {
            var id = $(this).attr('c-id');


            //获取该条数据的描述
            var desc = $('#desc-'+id).val();

            //获取该条数据的业务额区间
            var revenue_min = $('#revenue_min-'+id).val();
            var revenue_max = $('#revenue_max-'+id).val();

            var reg =  /^[0-9]+(\.[0-9]+)?$/;
            if(reg.test(revenue_min) == false || reg.test(revenue_max) == false) {
                layer.msg('请填写正确的业务额数据！',{icon:5,time:1500});
                return;
            }

            if (desc == '' && revenue_min == 0 && revenue_max == 0) {
                layer.msg('请填写配置内容！',{icon:5,time:1500});
            } else {
                $.ajax({
                    type: "post",
                    url: "star_level_config",
                    dataType: "json",
                    data: { id: id, revenue_min: revenue_min, revenue_max:revenue_max, desc:desc},
                    success: function(data){
                        if (data.code == 1) {
                            layer.msg(data.msg,{icon:5,time:1500});
                        } else {
                            layer.msg('修改成功',{icon:6,time:1500});
                        }
                    }, error: function(){
                        layer.msg("请求出错",{icon:5,time:1500});
                    }
                });
            }
        });
    });
</script>
{/block}